//
//  ProvinceController.m
//  NiuBanJinGold
//
//  Created by Billy on 15/11/11.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "ProvinceController.h"
#import "Province.h"
#import "CityViewController.h"

@interface ProvinceController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView; //数据源显示

@end

@implementation ProvinceController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self.navigationItem setTitle:@"选择省"];

    [self.view addSubview:self.tableView];
}


#pragma mark - TableView datasource && delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}


- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return [self.array_provinces count];
}


- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifer = @"cellProvince" ;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
    
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifer];
    }
    
    Province *tmp = [self.array_provinces objectAtIndex:indexPath.row];
    
    [cell.textLabel setText:tmp.province_name];
    
    return  cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    Province *tmp = [self.array_provinces objectAtIndex:indexPath.row]; //跳获得市的页面

    [UsefulUtil saveCustomObject:tmp intoUserDefaultByKey:@"province"];
    
    CityViewController *addressVC= [[CityViewController alloc] init];
    
    [addressVC setStr_id:tmp.province_id];
    
    [self.navigationController pushViewController:addressVC animated:YES];
}


#pragma mark - setter method

- (UITableView *)tableView {
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        [_tableView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    }
    
    return _tableView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
